#include "audiorecorder.h"

AudioRecorder::AudioRecorder(QObject *parent) : QObject(parent)
{
    /**
     * @brief seter
     * set base
     */
    QAudioEncoderSettings seter;
    seter.setBitRate(16);
    seter.setChannelCount(1);
    seter.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
    seter.setSampleRate(8000);
    seter.setCodec("amr");
    seter.setQuality(QMultimedia::HighQuality);

    audio_output_location="/mnt/sdcard/Android/data/baiduvoice.amr";

    /**
     * @recoder
     *
     */
    recoder=new QAudioRecorder();
    recoder->setOutputLocation(QUrl::fromLocalFile(audio_output_location));
    recoder->setEncodingSettings(seter, QVideoEncoderSettings(), "amr");
    connect(recoder,SIGNAL(statusChanged(QMediaRecorder::Status)),this,SLOT(onstatuschange()));
}

void AudioRecorder::startRecord (){
    recoder->record ();
    recordstausc=1;
    recordeStateChanged();
}
void AudioRecorder::stopRecord (){
    recoder->stop ();
    recordstausc=2;
    recordeStateChanged();
}
void AudioRecorder::onRecordStateChanged (){
    if(recoder->state()==QMediaRecorder::RecordingState)
        recordstausc=1;
    else if(recoder->state()==QMediaRecorder::StoppedState)
        recordstausc=2;
    else
        recordstausc=0;

    recordeStateChanged();
}
